<!DOCTYPE html>
<html lang="zh" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>新增文档 - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="images/favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<!--标签插件-->
<link rel="stylesheet" href="js/jquery-tags-input/jquery.tagsinput.min.css">
<link href="css/style.min.css" rel="stylesheet">
  <script src="js/head.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  <script src="js/login/login.js"></script>
  <script src="js/http.js"></script>
</head>
  
<body>
<div class="lyear-layout-web" id="vue">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    <aside class="lyear-layout-sidebar">

      <!-- logo -->
      <div id="logo" class="sidebar-header">
        <a href="index.html"><img src="images/logo-sidebar.png" title="LightYear" alt="LightYear" /></a>
      </div>
      <div class="lyear-layout-sidebar-scroll">

        <nav class="sidebar-main">
          <ul class="nav nav-drawer">
            <script src="js/leftNav.js"></script>
          </ul>
        </nav>

        <div class="sidebar-footer">
          <p class="copyright">Copyright &copy; 2019. <a target="_blank" href="http://lyear.itshubao.com">IT书包</a> All rights reserved.</p>
        </div>
      </div>

    </aside>
    <!--End 左侧导航-->
    

    
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-body">
                <div  class="row">
                  <div class="form-group col-md-12">
                    <label for="type">请选择课程类型</label>
                    <div class="form-controls">
                      <select name="type" class="form-control" id="type" v-model="typename">
                        <option v-for="list in courseClassifyList">{{list.typename}}</option>
                      </select>
                    </div>
                  </div>
                  <div class="form-group col-md-12">
                    <label >课程名</label>
                    <input type="text" class="form-control" placeholder="请输入课程名" v-model="title"/>
                  </div>
                  <div class="form-group col-md-12">
                    <label >课程简介</label>
                    <textarea class="form-control" rows="5"  placeholder="描述" v-model="synopsis"></textarea>
                  </div>
                  <div class="form-group col-md-12" id="uploadImg">
                    <label>上传预览图</label>
                    <div class="form-controls">
                      <ul class="list-inline clearfix lyear-uploads-pic"
                          id="show-uploaded-pic">
                        <input type="file" id="file"
                               style="display:none;" @change="uploadImg"/>
                        <li class="col-xs-4">
                          <a class="pic-add" id="add-pic-btn"
                             title="点击上传"></a>
                        </li>
                      </ul>
                    </div>
                  </div>
                  <div class="form-group col-md-12">
                    <label >是否收费</label>
                    <!--<input class="form-control" type="text" v-model="money"/>-->

                      <input type="radio" id="one" value="0"
                             v-model="charge" @change="chargeValue">
                      <label for="one" class="text-success">免费</label>
                      <input type="radio" id="two" value="1"
                             v-model="charge" @change="chargeValue">
                      <label for="two" class="text-danger">收费</label>
                     <input id="moneyText" style="display:none;" class="form-control" type="text" v-model="money" placeholder="请输入价格" />

                  </div>

                  <div class="form-group col-md-12">
                    <button type="button" class="btn btn-primary ajax-post" @click="addCourse" >确 定</button>
                    <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返 回</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<!--标签插件-->
<script src="js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>
</body>
</html>
<script type="text/javascript">

  $(document).ready(function () {
    //监听上传视频按钮
    $("#add-pic-btn").click(function () {
      $("#file").click();
    });
  });

  let vm=new Vue({
    el:'#vue',
    data:{
      courseClassifyList:"",
      typename:"",
      title:"",
      synopsis:"",
      money:"",
      imgUrl:"",
      charge:"",
    },
    methods:{
      /*添加课程*/
      addCourse:function () {
        console.log("addCourse");
        //this.$options.methods.upload();
        let title=vm.title;
        let synopsis=vm.synopsis;
        let typename=vm.typename;
        let imgUrl=vm.imgUrl;
        let money=vm.money;
        let charge=vm.charge;
        if (charge == 0) {
          money=0
        }
        $.ajax({
          type: 'POST',
          url: baseUrl+"education_admin/course/addCourse",
          data:{
            typename,
            title,
            synopsis,
            money,
            imgUrl,
            state:2,
            charge,
          },
          success:function (resp) {
            //let result = JSON.parse(resp);
            alert(resp.message);
            location.href="courseList.html";
          }
        })
      },
      /**
       * 上传图片
       */
      uploadImg:function () {
        let formData = new FormData();
        formData.append("file", $("#file")[0].files[0]);
        $.ajax({
          type: 'POST',
          url: baseUrl+"education_admin/upload/uploadFileWithRelativePath",
          cache: false,
          data: formData,
          processData: false,
          contentType: false,
          success: function (resp) {
            //let result = JSON.parse(resp);
            let url=baseUrl+"view/img/course/"+resp.data.videoUrl;
            vm.imgUrl=url;
            let html='<div class="col-xs-12"><img src="'+url+'"></div>';
            $("#uploadImg").replaceWith(html);
          }
        });
      },
      chargeValue:function () {
        if (vm.charge==1) {
          $("#moneyText").show()
        }else {
          $("#moneyText").hide()
        }
      }

    },
    mounted:function () {
      $.ajax({
        type:'GET',
        url:baseUrl+"education_admin/courseClassify/courseClassifyList",
        success:function (resp) {
          //let result = JSON.parse(resp);
          vm.courseClassifyList=resp.data;
        }
      })
    }
  })
</script>